<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC
  "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <title>{{ app_title }}</title>
        <link rel="stylesheet" type="text/css" href="/static/tasks_backup.css" />
        <link rel="shortcut icon" type="image/x-icon" href="/static/favicon.ico" />
        <link rel="icon" type="image/x-icon" href="/static/favicon.ico" />
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <script type="text/javascript">
            var secondsRemaining = {{ AUTH_RETRY_COUNT_COOKIE_EXPIRATION_TIME }};

            function authorise() {
                document.getElementById("authorise_button").value = "Authorising, please wait (this may take up to half a minute) ...";
                document.getElementById("authorise_button").innerHTML = "Authorising, please wait (this may take up to half a minute) ...";
                document.getElementById("authorise_button").disabled = true;
                window.location.href = "/auth";
            }
            
            function enableRetryButton() {
                if (secondsRemaining <= 0) {
                    document.getElementById("authorise_button").value = "Retry authorisation";
                    document.getElementById("authorise_button").innerHTML = "Retry authorisation";
                    document.getElementById("authorise_button").disabled = false;
                }
                else
                {
                    document.getElementById("authorise_button").value = "Please wait " + secondsRemaining.toString();
                    document.getElementById("authorise_button").innerHTML = "Please wait " + secondsRemaining.toString();
                    setTimeout("enableRetryButton()", 1000);
                }
                secondsRemaining--;
            }
            
        </script>
        <script type="text/javascript">

          var _gaq = _gaq || [];
          _gaq.push(['_setAccount', 'UA-30118203-1']);
          _gaq.push(['_trackPageview']);

          (function() {
            var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
            ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
            var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
          })();

        </script>
    </head>
  
  <body onload="enableRetryButton();">
    <h2>{{ app_title }}</h2>
  
    {% if host_msg %}
        <div class="break">
        <h4>{{ host_msg }}</h4>
        </div>
    {% endif %}

    <br/>
    <br/>
    
    {% comment %}
        The rc value indicates the reason for displaying the page
            NC = No credentials (Optionally includes nr param)
            IC = Invalid credentials (Optionally includes nr param)
            XC = None OR Invalid credentials (Optionally includes nr param)
            NU = No user
            EX = Exception (TODO: adds msg param, requires hexifying strings)
        The nr value is only used for NC and IC, and indicates the number of retries

    {% endcomment %}
    
    {% if rc == "NC" %}
        <!-- No credentials -->
        {% if nr %}
            <!-- Too many retries -->
            <h2>Unable to retrieve credentials, even after {{ nr }} tries.</h2>
        {% else %}
            <h2>Unable to retrieve credentials for this account.</h2>
        {% endif %}
    {% endif %}
    
    {% if rc == "IC" %}
        <!-- Invalid credentials -->
        {% if nr %}
            <!-- Too many retries -->
            <h2>Google reports that the credentials for this account are invalid, even after {{ nr }} tries.</h2>
        {% else %}
            <h2>Google reports that the credentials for this account are invalid.</h2>
        {% endif %}
    {% endif %}
    
    {% if rc == "XC" %}
        <!-- Invalid or no credentials -->
        {% if nr %}
            <!-- Too many retries -->
            <h2>Google reports that there are no credentials for this account, or that the credentials are invalid, even after {{ nr }} tries.</h2>
        {% else %}
            <h2>Google reports that there are no credentials for this account, or that the credentials are invalid.</h2>
        {% endif %}
    
    {% endif %}
    
    {% if rc == "NU" %}
        <h2>Unable to retrieve user details.</h2>
        <p>Please <a href="{{ url_home_page }}">retry</a>.
    {% endif %}
    
    {% if rc == "EX" %}
        <!-- Exception retrieving credentials -->
        <h2>Error retrieving credentials for this account.</h2>
        <p>Please report error {{ err }} at  <a href="http:/{{ url_issues_page }}">{{ url_issues_page }}</a></p>.
    {% endif %}
    
    {% if not rc %}
        <!-- Catch all -->
        <h2>Your credentials have expired, are invalid, or could not be verified.</h2>
    {% endif %}
    
    {% if msg %}
        <div class="break">
            {{ msg }}
        </div>
    {% endif %}
    
    <div class="break">
        This error could be because;
            <ul>
                <li>your session has timed out, OR</li>
                <li>your Google Apps account is not authorised to access this application, OR</li>
                <li>your account is not currently in good standing with Google, OR</li>
                <li>there has been a temporary server or communications error.
            </ul>
        Please wait at least {{ AUTH_RETRY_COUNT_COOKIE_EXPIRATION_TIME }} seconds before trying again.
    </div>
    <button id="authorise_button" class="big-button" type="button" disabled="disabled" onclick="authorise();">Retry authorisation</button>
    
    <br/>
    <br/>
    <div class="break take-note">If this happens again, please report the problem at <a href="http:/{{ url_issues_page }}">{{ url_issues_page }}</a>
    </div>
    
    
     <div class="break">
        In some circumstances, it may help to <a href="{{ logout_url }}">completely log out of your Google account</a> and then <a href="{{ url_home_page }}">restart  {{ app_title }}</a>. 
    </div>

   
    

    
    
	<div class="project-footer">
        <div class="break">
            Version {{ app_version }} ({{ upload_timestamp }})
        </div>
		<div class="break">
			Questions or comments? Go to <a href="http://{{ url_discussion_group }}">{{ url_discussion_group }}</a>
			or email <a href="mailto:{{ email_discussion_group }}">{{ email_discussion_group }}</a>
		</div>
		<div class="break">
			Please report bugs or suggest improvements at <a href="http:/{{ url_issues_page }}">{{ url_issues_page }}</a>
		</div>
		<div class="break">
			Source code for this project is at <a href="http://{{ url_source_code }}">{{ url_source_code }}</a>
		</div>
        <div class="break">
            {{ app_title }} version {{ app_version }} ({{ upload_timestamp }})
        </div>
        
	</div>

  </body>
</html>
